<template>
	<view class="job-page">
		<view class="list-box" v-if="list.length">
			<view class="item" v-for="(item, index) in list" :key="index" @click="selectJob(item)">
				<view class="left">
					<view class="company">{{ item.company }}</view>
					<view class="job">{{ item.job }}</view>
				</view>
				<view class="edit" @click.stop="editJob(item)">
					<u-icon name="edit-pen" color="#333" size="36rpx"></u-icon>
					<text class="text">编辑</text>
				</view>
			</view>
		</view>
		<view class="empty-box" v-else>
			<u-empty mode="list" text="暂无数据~"></u-empty>
		</view>

		<button class="add-btn" @click="addJob">
			<u-icon name="plus" color="#fff" size="32rpx" bold></u-icon>
			<text class="text">添加职位信息</text>
		</button>
		
		<u-popup :show="show" mode="center" round="20rpx" closeable :safeAreaInsetBottom="false" @close="show = false">
			<view class="popup-box">
				<view class="title">编辑职位身份</view>
				<view class="form-box">
					<view class="form-item">
						<input class="input" type="text" v-model="form.company" placeholder="企业名称" />
					</view>
					<view class="form-item">
						<input class="input" type="text" v-model="form.job" placeholder="职位" />
					</view>
				</view>
				<button class="btn">保存</button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data () {
			return {
				show: false,
				form: {
					id: '',
					company: '',
					job: '',
				},
				
				list: [{
					id: 0,
					company: '腾讯',
					job: '前端',
				}, {
					id: 1,
					company: '阿里巴巴',
					job: '后端',
				}],
			}
		},
		methods: {
			addJob () {
				this.form = {
					id: '',
					company: '',
					job: '',
				}
				
				this.show = true
			},
			editJob (form) {
				this.form = form
				
				this.show = true
			},
			selectJob (form) {
				uni.$emit('selectJob', form)
				
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
.job-page {
	padding: 28rpx;
	.list-box {
		.item {
			padding: 28rpx 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			& + .item {
				border-top: 1rpx solid #eee;
			}
			.left {
				flex: 1;
				.company {
					font-size: 34rpx;
				}
				.job {
					margin-top: 4rpx;
					font-size: 28rpx;
				}
			}
			.edit {
				display: flex;
				align-items: center;
				.text {
					margin-left: 4rpx;
					color: #333;
					font-size: 28rpx;
				}
			}
		}
	}
	.empty-box {
		height: 500rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.add-btn {
		margin-top: 88rpx;
		border-radius: 100rpx;
		height: 100rpx;
		line-height: 100rpx;
		background: linear-gradient(90deg, #29d144, #26bccf);
		display: flex;
		align-items: center;
		justify-content: center;
		.text {
			margin-left: 4rpx;
			color: #fff;
			font-size: 32rpx;
			font-weight: bold;
		}
	}
	.popup-box {
		width: 600rpx;
		padding: 34rpx 32rpx 60rpx;
		.title {
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
		}
		.form-box {
			margin-top: 40rpx;
			.form-item {
				padding: 0 20rpx;
				border-radius: 10rpx;
				background-color: #f8f8f8;
				& + .form-item {
					margin-top: 20rpx;
				}
				.input {
					width: 100%;
					height: 100rpx;
				}
			}
		}
		.btn {
			margin-top: 52rpx;
			border-radius: 100rpx;
			width: 360rpx;
			height: 100rpx;
			color: #fff;
			font-weight: bold;
			line-height: 100rpx;
			background: #333;
		}
	}
}
</style>
